﻿using Coldairarrow.Business;
using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_WorkStationController : BaseApiController
    {
        #region DI

        public PB_WorkStationController(IPB_WorkStationBusiness pB_WorkStationBus)
        {
            _pB_WorkStationBus = pB_WorkStationBus;
        }

        IPB_WorkStationBusiness _pB_WorkStationBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_WorkStationDTO>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_WorkStationBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_WorkStation> GetTheData(IdInputDTO input)
        {
            return await _pB_WorkStationBus.GetTheDataAsync(input.id);
        }


        [HttpPost]
   
        [AllowAnonymous]
        public async Task<PageResult<PB_WorkStation>> GetDataListByWorkshop(string workshopId)
        {
            return await _pB_WorkStationBus.GetDataListByWorkshopAsync(workshopId);
        }
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_WorkStation data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_WorkStationBus.AddDataAsync(data);
            }
            else
            {
                await _pB_WorkStationBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_WorkStationBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}